<template>
  <view class="content">
    <view class="video_con">
      <mescroll-body
        class="water_scroll"
        ref="mescrollRef"
        @init="mescrollInit"
        :down="downOption"
        @down="downCallback"
        @up="upCallback"
      >
        <view class="video_list" :key="index">
          <!-- v-for="(item,index) in dataList" -->
          <view class="video_intro">
            <view class="intro">
              <text>位置：A区1栋3楼转角</text>
              <text class="normal">A5201</text>
            </view>
          </view>
          <view class="video_title">
            <view class="intro">
              <text>红外摄像头</text>
              <text style="color: #44d94b">正常</text>
            </view>
          </view>
        </view>
        <view class="video_list" :key="index">
          <!-- v-for="(item,index) in dataList" -->
          <view class="video_intro">
            <view class="intro">
              <text>位置：A区1栋3楼转角</text>
              <text class="trouble">A5201</text>
            </view>
          </view>
          <view class="video_title">
            <view class="intro">
              <text>红外摄像头</text>
              <text style="color: #f74d39">故障</text>
            </view>
          </view>
        </view>
      </mescroll-body>
    </view>
  </view>
</template>

<script>
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
export default {
  mixins: [MescrollMixin], // 使用mixin
  data() {
    return {
      dataList: [],
      downOption: {
        page: {
          num: 0,
          size: 10,
          time: null,
        },
        auto: false, //是否在初始化后,自动执行downCallback; 默认true
      },
      dictList: [],
    };
  },
  onLoad(option) {
    this.getDict();
  },
  methods: {
    getDict() {
      //联网加载数据
      this.apis.commonApi
        .getDict("enterprise_type")
        .then((res) => {
          this.dictList = res.data;
        })
        .catch(() => {
          //联网失败的回调,隐藏下拉刷新的状态
        });
    },
    /*下拉刷新的回调 */
    downCallback(page) {
      let that = this;
      //联网加载数据
      this.apis.businessApi
        .qyEnterpriseList({
          pageNum: page.num,
          pageSize: page.size,
        })
        .then((res) => {
          // this.dataList=res.rows
          const rows = res.rows;
          for (let i = 0; i < rows.length; i++) {
            let enterpriseType = rows[i].enterpriseType;
            for (let j = 0; j < this.dictList.length; j++) {
              let dictValue = this.dictList[j].dictValue;
              if (enterpriseType == dictValue) {
                rows[i].enterpriseType = this.dictList[j].dictLabel;
              } else {
                rows[i].enterpriseType = "未知";
              }
            }
          }
          this.dataList = rows;
          this.mescroll.endBySize(res.rows.length, res.total);
        })
        .catch(() => {
          //联网失败的回调,隐藏下拉刷新的状态
          this.mescroll.endErr();
        });
    },
    /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
    upCallback(page) {
      //联网加载数据
      this.apis.businessApi
        .qyEnterpriseList({
          pageNum: page.num,
          pageSize: page.size,
        })
        .then((res) => {
          this.dataList = this.dataList.concat(res.rows);
          this.mescroll.endBySize(res.rows.length, res.total);
        })
        .catch(() => {
          //联网失败的回调,隐藏下拉刷新的状态
          this.mescroll.endErr();
        });
    },
  },
};
</script>

<style lang="scss" scoped>
page {
  padding: 0;
}

.content {
  .video_con {
    overflow-y: auto;
    // height: 1160rpx;
    margin: 20rpx 20rpx 0 20rpx;
  }

  .video_list {
    padding: 24rpx 30rpx;
    box-sizing: border-box;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    margin-bottom: 20rpx;
    border-radius: 12rpx;
    .video_intro,
    .video_title {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      color: #333333;
      .intro {
        display: flex;
        font-size: 28rpx;
        justify-content: space-between;
        text:nth-child(2) {
          font-size: 26rpx;
        }
        .trouble {
          padding: 4rpx 10rpx;
          background-color: rgba($color: #44d94b, $alpha: 0.15);
          border-radius: 2rpx;
          font-size: 24rpx;
          color: #44d94b;
        }
        .normal {
          padding: 4rpx 10rpx;
          background-color: rgba($color: #f74d39, $alpha: 0.15);
          border-radius: 2rpx;
          font-size: 24rpx;
          color: #f74d39;
        }
      }
    }
    .video_intro {
      padding-bottom: 20rpx;
      border-bottom: 1rpx solid #eeeeee;
    }
    .video_title {
      padding-top: 20rpx;
      .intro {
        font-size: 26rpx;
        color: #999999;
      }
    }
  }
}
</style>
